import router from "./index";
import NProgress from "nprogress";
import 'nprogress/nprogress.css' // progress bar style
import settings from "../setting.ts";
import { getToken, setToken} from '@/unit/cookies';
import { settingName } from '@/unit/index.ts'

router.beforeEach(async (to, from, next) =>{
  setToken()
  NProgress.start()
  const hasToken = getToken()
  console.log('123')
  if(!hasToken){
    console.log('123435')
    // try {
    //   // console.log(RoleRoutes)
    //   router.addRoute(routerObj)
    //   // {
    //   //   path: to.path,
    //   //   replace: true
    //   // }
    //   // next({path: to.path, replace: true})
    //   next()
    // } catch (error) {
    //   console.log(error)
    // }
    next()
  }else{
    next()
  }
})

router.afterEach((to) => {
  // Finish progress bar    完成进度条
  NProgress.done()
  // set page title     设置页面标题
  document.title = settingName(to) + '-' + settings.title
  // console.log(router)
})